package com.icloud.system.boot.controller.app;

import com.icloud.common.core.api.CommonResult;
import com.icloud.common.web.annotation.AppOperationLog;
import com.icloud.common.web.annotation.AppWhiteListOperationLog;
import com.icloud.system.boot.dto.AddAppCustomerDto;
import com.icloud.system.boot.dto.HomeBrowsedPageDto;
import com.icloud.system.boot.dto.UpdateAppCustomerDto;
import com.icloud.system.boot.service.AppCustomerService;
import com.icloud.system.boot.service.HomeBrowsedService;
import com.icloud.system.boot.vo.AddAppCustomerVo;
import com.icloud.system.boot.vo.HomeBrowsedPageVo;
import com.icloud.system.boot.vo.ProfileVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "客户账户服务")
@RequestMapping("/app/customer")
@RequiredArgsConstructor
public class CustomerController {
    private final AppCustomerService appCustomerService;
    private final HomeBrowsedService homeBrowsedService;

    @ApiOperation("创建前台客户账号")
    @PostMapping("/add")
    @ResponseBody
    public CommonResult<AddAppCustomerVo> add(@Validated @RequestBody AddAppCustomerDto dto){
        return CommonResult.success(appCustomerService.add(dto));
    }

    @ApiOperation("编辑账户")
    @PostMapping("/edit")
    public CommonResult<Boolean> edit(@Validated @RequestBody UpdateAppCustomerDto dto){
        return CommonResult.success(appCustomerService.edit(dto));
    }

    @ApiOperation("客户信息(我的)")
    @GetMapping("/profile")
    @ResponseBody
    public CommonResult<ProfileVo> profile(@RequestParam("id") Long id){
        return CommonResult.success(appCustomerService.profile(id));
    }

    @ApiOperation("主页浏览记录分页查询")
    @PostMapping("/homeBrowsed/page")
    public CommonResult<HomeBrowsedPageVo> homeBrowsedPage(@Validated @RequestBody HomeBrowsedPageDto dto){
        return CommonResult.success(homeBrowsedService.homeBrowsedPage(dto));
    }
}
